package com.smart.campus.web.controller.school;

import java.util.List;

import com.smart.campus.common.utils.DateUtils;
import com.smart.campus.framework.util.ShiroUtils;
import com.smart.campus.school.domain.ExamRoomSchedule;
import com.smart.campus.web.utils.SchoolUtil;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.smart.campus.common.annotation.Log;
import com.smart.campus.common.enums.BusinessType;
import com.smart.campus.school.domain.RoomInfo;
import com.smart.campus.school.service.IRoomInfoService;
import com.smart.campus.common.core.controller.BaseController;
import com.smart.campus.common.core.domain.AjaxResult;
import com.smart.campus.common.utils.poi.ExcelUtil;
import com.smart.campus.common.core.page.TableDataInfo;

/**
 * 教室信息Controller
 * 
 * @author Zhihe.Li
 * @date 2020-06-28
 */
@Controller("roomInfo")
@RequestMapping("/school/roomInfo")
public class RoomInfoController extends BaseController
{
    private String prefix = "school/roomInfo";

    @Autowired
    private IRoomInfoService roomInfoService;

    @RequiresPermissions("school:roomInfo:view")
    @GetMapping()
    public String roomInfo()
    {
        return prefix + "/roomInfo";
    }

    /**
     * 查询教室信息列表
     */
    @RequiresPermissions("school:roomInfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(RoomInfo roomInfo)
    {
        startPage();
        roomInfo.setSchoolId(SchoolUtil.getSchoolId());
        List<RoomInfo> list = roomInfoService.selectRoomInfoList(roomInfo);
        return getDataTable(list);
    }

    /**
     * 导出教室信息列表
     */
    @RequiresPermissions("school:roomInfo:export")
    @Log(title = "教室信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(RoomInfo roomInfo)
    {
        roomInfo.setSchoolId(SchoolUtil.getSchoolId());
        List<RoomInfo> list = roomInfoService.selectRoomInfoList(roomInfo);
        ExcelUtil<RoomInfo> util = new ExcelUtil<RoomInfo>(RoomInfo.class);
        return util.exportExcel(list, "roomInfo");
    }

    /**
     * 新增教室信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存教室信息
     */
    @RequiresPermissions("school:roomInfo:add")
    @Log(title = "教室信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(RoomInfo roomInfo)
    {
        roomInfo.setSchoolId(SchoolUtil.getSchoolId());
        roomInfo.setCreateBy(ShiroUtils.getSysUser().getUserName());
        roomInfo.setCreateTime(DateUtils.getNowDate());
        return toAjax(roomInfoService.insertRoomInfo(roomInfo));
    }

    /**
     * 修改教室信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        RoomInfo roomInfo = roomInfoService.selectRoomInfoById(id);
        mmap.put("roomInfo", roomInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存教室信息
     */
    @RequiresPermissions("school:roomInfo:edit")
    @Log(title = "教室信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(RoomInfo roomInfo)
    {
        roomInfo.setUpdateBy(ShiroUtils.getSysUser().getUserName());
        roomInfo.setUpdateTime(DateUtils.getNowDate());
        return toAjax(roomInfoService.updateRoomInfo(roomInfo));
    }

    /**
     * 获取考试计划
     */
    @GetMapping("/getRoomList")
    public String getRoomList() {
        return prefix+"/query";
    }

    /**
     * 删除教室信息
     */
    @RequiresPermissions("school:roomInfo:remove")
    @Log(title = "教室信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(roomInfoService.deleteRoomInfoByIds(ids));
    }

    /**
     * 查询教室信息列表
     */
    @PostMapping("/getRoomListDict")
    @ResponseBody
    public List<RoomInfo> getRoomListDict()
    {
        RoomInfo roomInfo = new RoomInfo();
        roomInfo.setSchoolId(SchoolUtil.getSchoolId());
        List<RoomInfo> list = roomInfoService.selectRoomInfoList(roomInfo);
        return list;
    }
}
